local skel = fk.CreateSkill {
  name = "emo__xiju",
}

Fk:loadTranslationTable{
  ["emo__xiju"] = "喜锯",
  [":emo__xiju"] = "你于出牌阶段使用牌时，若本阶段你使用的牌点数严格递增，你摸一张牌并令本回合与其他角色计算距离时-1。然后你可以对一名距离为1的角色造成1点伤害并结束本回合。",

  ["#emo__xiju-choose"] = "你可以对一名距离为1的角色造成1点伤害并结束本回合",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) and player.phase == Player.Play then
      local num, good
      player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data
        if use.from == player then
          local n = use.card.number
          if not num then
            num = n
          elseif n > num then
            good = true
            num = n
          else -- 失败
            good = false
            return true
          end
        end
      end, Player.HistoryPhase)
      return good
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:drawCards(1, skel.name)
    if player.dead then return end
    room:addPlayerMark(player, "emo__xiju-phase")
    local targets = table.filter(room.alive_players, function (p)
      return player:distanceTo(p) == 1
    end)
    if #targets == 0 then return end
    local tos = room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = targets, skill_name = skel.name,
      prompt = "#emo__xiju-choose",
    })
    if #tos > 0 then
      room:damage { from = player, to = tos[1], damage = 1, skillName = skel.name }
      room:endTurn()
    end
  end,
})

skel:addEffect("distance", {
  correct_func = function (self, from, to)
    return - from:getMark("emo__xiju-phase")
  end,
})

return skel
